<?php

namespace app\admin\controller;

use think\facade\Db;
use think\facade\Request;

class Chapters extends Common
{

    public function addMaterials()
    {
        $selects = explode(",",Request::param('selects'));

        $chapter_id = Request::param('chapter_id');

        foreach ($selects as $v) {
            $data = ['material_id' => $v, 'chapter_id' => $chapter_id];

            $info = Db::name('chapters_materials')->where($data)->find();

            if (!$info) {
                Db::name('chapters_materials')->insert($data);
            }
        }

        singleJson(true);
    }


}
